﻿using Microsoft.AspNetCore.Mvc;
using RobosimAPI.Class;

namespace RobosimAPI.Controllers
{
	[Route("back/Api2/Client/checkSubmitRobosimScoreStatus")]
	public class CheckSubmitRobosimScoreStatusController : ControllerBase
	{
		[HttpPost]
		public IActionResult CheckSubmitRobosimScoreStatus([FromForm] CheckSubmitRobosimScoreStatusModel model)
		{
			Round round = new Round(model.round_id);
			Group group = new Group(round.GroupId);
			Event @event = new Event(group.event_id);
			string tableName = @event.db_name;
			Score score = new Score(tableName, model.user_id, model.round_id);
			if (!score.is_valid)
			{
				return Ok(new ErrorResponse{status=-1, errmsg= "Has not apply" });
			}
			if (round.IsExam!=1)
			{
				return Ok(new CheckSubmitRobosimScoreStatusResponse { status = 1, data = new Data { submit = 1 } });
			}
			return Ok(new CheckSubmitRobosimScoreStatusResponse{status=1, data=new Data{submit=score.limit} });
		}
		public class CheckSubmitRobosimScoreStatusModel
		{
			public int user_id { get; set; }
			public int round_id { get; set; }
		}
		public class Data
		{
			public int submit { get; set; }
		}
		public class CheckSubmitRobosimScoreStatusResponse
		{
			public int status { get; set; }
			public Data data { get; set; }
		}

	}
}
